/**
 * Created by Administrator on 2016/3/2.
 */
gpNamespace.MyTilesLayer = gpNamespace.ParentTilesLayer.extend({
	counterPosition: [cc.p(168, 250),cc.p(1099, 420), cc.p(600,560), cc.p(168, 440)],

	unTrustClicked: true,
	tileSpace: 45,
	fromPoint: cc.p(cc.winSize.width / 2, 100),

	fapaiEnd: false,

	lessSprite: null,
	guize: null,
	myGoldLayer:null,

	myListener: null,
	added:false,

    init: function () {
    	this._super();
    	
    	this.chuPointStart = cc.p(cc.winSize.width / 2, 280);
    	
        var runningScene = cc.director.getRunningScene();
        var prepareLayer = runningScene.getChildByName(gpNamespace.GamePrepareLayerName);
        cc.spriteFrameCache.addSpriteFrames(gpNamespace.pdkgamesenceRes.Pdkgamesence_plist);
//        cc.spriteFrameCache.addSpriteFrames(gpNamespace.gameRes.Game_plist);
        if (prepareLayer) {
        	var myHeadLayer = prepareLayer.getChildByName("headLayer0");
        	myHeadLayer.setPosition(-480, 30);
        	
        	var myGoldLayer = myHeadLayer.getChildByName("goldLayer");
        	myGoldLayer.setPosition(-130, -90);
        	//设置我的金币图标位置
        	var goldNode = myHeadLayer.getChildByName("goldNode");
        	goldNode.setPosition(500, 133);
        	//判断是否vip
        }
       
        //消息按钮
        var messageItem = new cc.MenuItemImage(gpNamespace.pdkgame.Game_message, gpNamespace.pdkgame.Game_message, this.messageCallbackFunction, this);
        messageItem.attr({
            x: 100 / 2,
            y: 100 / 2
        });
        var messageMenu = new cc.Menu(messageItem);
        messageMenu.attr({
            x: 1120,
            y: 38
        });
        this.addChild(messageMenu,30,"messageMenu");

        this.tishiLayer = new cc.Layer();
        this.addChild(this.tishiLayer, 10000);
        //黑色的标签底部
        var blackLabel = new cc.Sprite(gpNamespace.pdkgame.Game_inforbg);
        blackLabel.attr({
        	x: cc.winSize.width / 2,
        	y: 150,
        	anchorX: 0.5,
        	anchorY: 0.5
        });
        this.tishiLayer.addChild(blackLabel);
        blackLabel.setVisible(false);
        this.blackLabel = blackLabel;
        
        //你的出牌不符合规则
        var guize = new cc.Sprite(gpNamespace.pdkgame.Game_inforbufuheguizhe);
        guize.attr({
        	x: cc.winSize.width / 2,
        	y: 150,
        	anchorX: 0.5,
        	anchorY: 0.5
        });
        this.tishiLayer.addChild(guize,2);
        guize.setVisible(false);
        this.guize = guize;
        
        //您没有大过上家的牌
        var lessSprite = new cc.Sprite(gpNamespace.pdkgame.Game_informeiyoudapai);
        lessSprite.attr({
        	x: cc.winSize.width / 2,
        	y: 150,
        	anchorX: 0.5,
        	anchorY: 0.5
        });
        this.tishiLayer.addChild(lessSprite,2);
        lessSprite.setVisible(false);
        this.lessSprite = lessSprite;
    },

    settingCallbackFunction:function(){
    	cc.log("设置");
    },

    messageCallbackFunction:function(){
    	cc.log("聊天");
    	//按钮音效特效
    	gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

//    	var scaleSmall = new cc.ScaleTo(5 / 60, 0.95, 0.95);
//    	var scaleBig = new cc.ScaleTo(5 / 60, 1, 1);
//    	var clickAction = new cc.Sequence(scaleSmall, scaleBig);
//
//    	clickAction.easing(cc.easeCircleActionInOut());
//    	sender.runAction(clickAction);

    	var runningScene = cc.director.getRunningScene();
    	var tyModelLayer1 = new tyNamespace.TyModelLayer1();
    	var tyModelLayer = new tyNamespace.TyModelLayer();
    	tyModelLayer.setTouchArea(cc.size(667, 385), cc.p(317, 0));
    	tyModelLayer1.addChild(tyModelLayer);
    	runningScene.addChild(tyModelLayer1, 10);

    	var messageLayer = new gpNamespace.LtLayer();
    	messageLayer.attr({
    		x: 0,
    		y: -cc.winSize.height
    	});
    	tyModelLayer.addChild(messageLayer);

    	messageLayer.runAction(cc.moveBy(20 / 60, cc.p(0, cc.winSize.height)).easing(cc.easeSineOut()));
    },
    
//    drawChuButton: function () {
//    	cc.log("button==================================");
//    	if (this.player.status == tyNamespace.PlayerStatus.AutoPlay)
//    		return;
//
//    	var chuButtonLayer = new cc.Layer();
//    	this.addChild(chuButtonLayer, 1, 3);
//
//    },
    
    //监听器
    addMyListener: function () {
    	var self = this;
    	var beginPos = null;
    	var currentIndex = -1;
    	var currentMovePos = cc.p(0, 0);
    	var toRight = false;
    	var lastTo = null;
    	var dela = 0;

    	var touchListener = cc.EventListener.create({
    		event: cc.EventListener.TOUCH_ONE_BY_ONE,
    		swallowTouches: true,                       // 设置是否吞没事件，在 onTouchBegan 方法返回 true 时吞没

    		initCick: function (pos) {
    			currentIndex = -1;
    			currentMovePos = pos;
    			toRight = false;
    			lastTo = null;
    		},

    		onTouchBegan: function (touch, event) {     //实现 onTouchBegan 事件回调函数
    			if (!self.fapaiEnd) {
    				cc.log("发牌没结束");
    				return false;
    			}

    			beginPos = self.convertTouchToNodeSpace(touch); //当前事件发生的位置

    			var isClick = cc.rectContainsPoint(cc.rect(self.startPoint.x - self.tileSpace / 2, self.startPoint.y - 198 / 2, (self.player.handTiles.length - 1) * self.tileSpace + 138, 198), beginPos);

    			this.initCick(beginPos);

    			if (!isClick)
    				self.resetTilesPositionNormal();

    			return isClick;
    		},

    		onTouchMoved: function (touch, event) {
    			if (!self.player.handTiles || self.player.handTiles.length == 0)
    				return false;

    			var movePos = self.convertTouchToNodeSpace(touch);

    			toRight = movePos.x - currentMovePos.x > dela;

    			var isTurn = lastTo != toRight;

    			if (isTurn)
    				lastTo = toRight;

    			this.moveTiles(movePos, isTurn);

    			currentMovePos = movePos;
    		},

    		onTouchEnded: function (touch, event) {
    			if (!self.player.handTiles || self.player.handTiles.length == 0)
    				return false;

    			var endPos = self.convertTouchToNodeSpace(touch);

    			var isTurn = lastTo != toRight;

    			if (isTurn)
    				lastTo = toRight;

    			this.moveTiles(endPos, isTurn);

    			gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.XuanpaiEffect, false);

    			self.updateButtonState(self.getChuTiles());
    		},

    		moveTiles: function (pos, isTurn) {
    			for (var a = 0; a < self.player.handTiles.length; a++) {
    				var minPosX = self.startPoint.x - self.tileSpace / 2 + a * self.tileSpace;
    				var maxPosX = self.startPoint.x - self.tileSpace / 2 + (a + 1) * self.tileSpace;
    				if (a == self.player.handTiles.length - 1)
    					maxPosX = self.startPoint.x - self.tileSpace / 2 + (self.player.handTiles.length - 1) * self.tileSpace + 138;
    				if (pos.x > minPosX && pos.x < maxPosX) {
    					if (currentIndex != a || isTurn) {
    						currentIndex = a;
    						self.tileUp(self.player.handTiles[a]);
    					}
    				}
    			}
    		}
    	});

    	this.myListener = touchListener;

    	cc.eventManager.addListener(touchListener, this);
    },
    
    tileUp: function (currentTile) {
    	if (currentTile.clickTime == 0) {
    		currentTile.clickTime = 1;
    		currentTile.sprite.runAction(cc.moveBy(0.1, 0, 20));
    	}
    	else {
    		currentTile.clickTime = 0;
    		currentTile.sprite.runAction(cc.moveBy(0.1, 0, -20));
    	}
    },
    
    //更新按钮状态
    updateButtonState: function (chuTiles) {
    	var chuButtonLayer = this.getChildByTag(3);

    	if (!chuButtonLayer)
    		return;

    	var chuMenu = chuButtonLayer.getChildByTag(4);
    	if (!chuMenu)
    		return;

    	var zhao = chuButtonLayer.getChildByTag(5);

    	var component = gpNamespace.CardActions.generateComponent(chuTiles);

    	if (component) {
    		if (zhao)
    			zhao.removeFromParent(true);
    	} else if (!zhao) {
    		zhao = new cc.Sprite("#ddz_jm_013u.png");
    		zhao.setPosition(chuMenu.getPosition());
    		chuButtonLayer.addChild(zhao, 1, 5);
    	}
    },

    oneCallbackFunction: function (sender) {
//    	gpNamespace.playEffect(gpNamespace.soundRes.ButtonEffect, false);

    	gpNamespace.callGrab(true, false, 1);
    },

    twoCallbackFunction: function (sender) {
//    	gpNamespace.playEffect(gpNamespace.soundRes.ButtonEffect, false);

    	gpNamespace.callGrab(true, false, 2);
    },

    threeCallbackFunction: function (sender) {
//    	gpNamespace.playEffect(gpNamespace..ButtonEffect, false);

    	gpNamespace.callGrab(true, false, 3);
    },

    superGrabCallbackFunction: function (sender) {
//    	gpNamespace.playEffect(gpNamespace..ButtonEffect, false);

    	if(!this.added){
    		//使用超级抢地主
    		xinyou.netManager.usePropBefore(42);
    		//xinyou.netManager.useProp(42, 0);

    		this.added = true;
    		this.scheduleOnce(function () {
    			this.added = false;
    		}, 2);
    	}
    	//gpNamespace.callGrab(true, true);
    },

    cancelGrabCallbackFunction: function (sender) {
//    	gpNamespace.playEffect(gpNamespace.soundRes.ButtonBack, false);

    	gpNamespace.callGrab(false, false);
    },

    removeGrabLayer: function (sender) {
    	this.removeChildByTag(2);
    },

    drawTiles: function (myTiles) {
    	this.showTiles(myTiles);
    },
    
    runChuActionOnline: function (tiles) {
    	this._super(tiles);

    	var myTiles = this.player.handTiles;

    	for (var i = 0; i < tiles.length; i++) {
    		var tile = tiles[i];
    		var index = gpNamespace.CardActions.getTileIndex(tile, myTiles);
    		if (index >= 0) {
    			this.player.splice(index, 1);
    		}
    	}

    	this.startPoint.x += tiles.length * this.tileSpace / 2;

    	this.resetTilesPositionNormal();
    },

    //添加取消托管按钮
    addTrustMenu: function () {
    	cc.log("addTrustMenu: tuoguan ");
    	
    	//黑色遮罩
    	var modelLayer = new tyNamespace.ModelLayer();

    	var tuoguanLayer = cc.Layer();
    	modelLayer.addChild(tuoguanLayer);

    	this.addChild(modelLayer, 50, "tuoguanLayer");

    	//取消托管图标
	  	var tuoguanphoto = new cc.Sprite(gpNamespace.pdkgame.Game_tuogaunzhong);
		  	tuoguanphoto.attr({
		  	x: 18,
		  	y: 245,
		  	anchorX: 0,
		  	anchorY: 0
		  	});
		tuoguanLayer.addChild(tuoguanphoto, 5);
	  	
		//取消托管按钮
		var tuoguanItem = new cc.MenuItemSprite(new cc.Sprite(gpNamespace.pdkgame.Game_buttonquxiaotuoguan),new tyNamespace.maskSprite(gpNamespace.pdkgame.Game_buttonquxiaotuoguan),
    			this.unTrust, this);
    	
    	var tuoguanMenu = new cc.Menu(tuoguanItem);
    	tuoguanMenu.attr({
    		x:cc.winSize.width / 2,
    		y:cc.winSize.height / 2 - 280,
    	});

    	tuoguanLayer.addChild(tuoguanMenu);
    	
    	this.unTrustClicked = false;

    	this.player.status = tyNamespace.PlayerStatus.AutoPlay;
    	
    	if(this.getChildByName("spriteRemoved") != null){
    		this.getChildByName("spriteRemoved").removeFromParent(true);
    	}
    },

    call1BackRemove: function (armature, movementType, movementID) {   
    	if (movementType == ccs.MovementEventType.complete) {   
    		armature.removeFromParent(true);

    		var trustBanner = this.getChildByTag(this.trustBannerTag);
    		if (trustBanner == null) {
    			var trustBanner = new cc.Sprite("#mj_tg_003u.png");
    			trustBanner.attr({
    				x: 413,
    				y: 442,
    				anchorX: 0,
    				anchorY: 0
    			});
    			this.addChild(trustBanner, 1002, this.trustBannerTag);
    		}
    		trustBanner.setVisible(true);

    		var trustLabel = this.getChildByTag(this.trustLabelTag);
    		if (trustLabel == null) {
    			var trustLabel = new cc.Sprite("#mj_tg_002u.png");
    			trustLabel.attr({
    				x: 588,
    				y: 450,
    				anchorX: 0,
    				anchorY: 0
    			});
    			this.addChild(trustLabel, 1002, this.trustLabelTag);
    		}
    		trustLabel.setVisible(true);

    		var trustArmatureDot = this.getChildByTag(this.trustDotTag);
    		if (trustArmatureDot != null) {
    			trustArmatureDot.removeFromParent(true);
    		}
    		trustArmatureDot = new ccs.Armature("robit_02a");
    		trustArmatureDot.getAnimation().play("robit");
    		trustArmatureDot.getAnimation().setSpeedScale(1);
    		trustArmatureDot.setScale(1);
    		trustArmatureDot.setAnchorPoint(0.5, 0.5);
    		trustArmatureDot.setPosition(700, 470);
    		this.addChild(trustArmatureDot, 1002, this.trustDotTag);

    		var trustArmature = new ccs.Armature("robit_01a");
    		trustArmature.getAnimation().play("robit_02a");
    		trustArmature.getAnimation().setSpeedScale(1);
    		trustArmature.setScale(1);
    		trustArmature.setAnchorPoint(0.5, 0.5);
    		trustArmature.setPosition(640, 550);
    		this.addChild(trustArmature, 1001);
    		trustArmature.getAnimation().setMovementEventCallFunc(this.call2BackRemove, this);
    	}
    },

    call2BackRemove: function (armature, movementType, movementID) {
    	if (movementType == ccs.MovementEventType.complete) {
    		armature.removeFromParent(true);

    		var trustArmature = new ccs.Armature("robit_01a");
    		trustArmature.getAnimation().play("robit_03a");
    		trustArmature.getAnimation().setSpeedScale(1);
    		trustArmature.setScale(1);
    		trustArmature.setAnchorPoint(0.5, 0.5);
    		trustArmature.setPosition(640, 550);
    		this.addChild(trustArmature, 1001);
    		trustArmature.getAnimation().setMovementEventCallFunc(this.call3BackRemove, this);
    	}
    },

    call3BackRemove: function (armature, movementType, movementID) {
    	if (movementType == ccs.MovementEventType.complete) {
    		armature.removeFromParent(true);

    		var trustArmature = new ccs.Armature("robit_01a");
    		trustArmature.getAnimation().play("s_robit_01a");
    		trustArmature.getAnimation().setSpeedScale(1);
    		trustArmature.setScale(1);
    		trustArmature.setAnchorPoint(0.5, 0.5);
    		trustArmature.setPosition(72, 462);
    		this.addChild(trustArmature, 1001);
    		trustArmature.getAnimation().setMovementEventCallFunc(this.call4BackRemove, this);
    	}
    },

    call4BackRemove: function (armature, movementType, movementID) {
    	if (movementType == ccs.MovementEventType.complete) {
    		armature.removeFromParent(true);

    		var trustArmature = this.getChildByTag(this.trustArmatureTag);
    		if (trustArmature != null) {
    			trustArmature.removeFromParent(true);
    		}
    		trustArmature = new ccs.Armature("robit_01a");
    		trustArmature.getAnimation().play("s_robit_02a");
    		trustArmature.getAnimation().setSpeedScale(1);
    		trustArmature.setScale(1);
    		trustArmature.setAnchorPoint(0.5, 0.5);
    		trustArmature.setPosition(72, 460);
    		this.addChild(trustArmature, 1001, this.trustArmatureTag);

    		this.schedule(this.playRobot, 3);

    		var trustMenu = this.getChildByTag(this.trustMenuTag);
    		if (trustMenu == null) {
    			var trustMenuItem = new cc.MenuItemImage(
    					"#mj_tg_004u.png",
    					"#mj_tg_004u.png",
    					this.unTrust, this);
    			trustMenuItem.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.3, 1.01, 1.02), cc.scaleTo(0.6, 0.99, 0.99), cc.scaleTo(0.3, 1, 1))));
    			trustMenuItem.runAction(cc.repeatForever(cc.sequence(cc.tintTo(0.3, 255, 255, 255), cc.tintTo(0.6, 200, 200, 200), cc.tintTo(0.3, 255, 255, 255))));
    			trustMenu = new cc.Menu(trustMenuItem);
    			trustMenu.setPosition(640, 360);
    			this.addChild(trustMenu, 1002, this.trustMenuTag);
    			trustMenu.setUserData(trustMenuItem);
    		}
    		trustMenu.setVisible(true);
    	}
    },

    //定时播放小机器
//    playRobot: function () {
//    	var trustArmature = this.getChildByTag(this.trustArmatureTag);
//    	trustArmature.getAnimation().play("s_robit_02a");
//    },

    //取消托管
    unTrust: function () {
    	cc.log("取消托管=============");
    	
    	gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
    	
//    	var tuoguanLayer = this.getChildByName("tuoguanLayer");  //设置取消托管按钮隐藏
//    	if (tuoguanLayer)
//    		tuoguanLayer.removeFromParent(true);
    	
    	if (this.unTrustClicked){
    		return;
    	}
    	
//    	this.unTrustClicked = true;
//    	
//    	this.player.status = tyNamespace.PlayerStatus.Playing;
//    	var trustMenu = this.getChildByTag(this.trustMenuTag);
//    	trustMenu && trustMenu.setVisible(false);
    	gpNamespace.setTuoguan(false);
    },

    call5BackRemove: function (armature, movementType, movementID) {
    	if (movementType == ccs.MovementEventType.complete) {
    		armature.removeFromParent(true);
    	}
    },

    toUnTrust: function () {
    	var trustMenu = this.getChildByTag(this.trustMenuTag);
    	if (trustMenu != null && trustMenu.isVisible())
    		this.unTrust(trustMenu.getUserData());
    },

    drawChuButton: function () {
    	cc.log("drawChuButton=============================");
    	
    	if (this.player.status == tyNamespace.PlayerStatus.AutoPlay)
    		return;

    	var chuButtonLayer = this.getChildByName("spriteRemoved");
    	if (!chuButtonLayer) {
    		chuButtonLayer = new cc.Layer();
    		this.addChild(chuButtonLayer, 20, "spriteRemoved");
    	}

/*    	//顺子按钮，同花按钮，夫佬按钮，四条按钮，同花顺按钮
    	var shunzi = new cc.MenuItemSprite(new cc.Sprite(gpNamespace.game.Game_blackshunzi),new tyNamespace.maskSprite(gpNamespace.game.Game_writeshunzi),
    			this.fivetishiCallbackFunction, this);
    	shunzi.setUserData(11);

    	var tonghua = new cc.MenuItemSprite(new cc.Sprite(gpNamespace.game.Game_blacktonghua),new tyNamespace.maskSprite(gpNamespace.game.Game_writetonghua),
    			this.fivetishiCallbackFunction, this);
    	tonghua.setUserData(12);
    	
    	var fulao = new cc.MenuItemSprite(new cc.Sprite(gpNamespace.game.Game_blackfulao),new tyNamespace.maskSprite(gpNamespace.game.Game_writefulao),
    			this.fivetishiCallbackFunction, this);
    	fulao.setUserData(13);
    	
    	var sitiao = new cc.MenuItemSprite(new cc.Sprite(gpNamespace.game.Game_blacksitiao),new tyNamespace.maskSprite(gpNamespace.game.Game_writesitiao),
    			this.fivetishiCallbackFunction, this);
    	sitiao.setUserData(15);
    	
    	var tonghuashun = new cc.MenuItemSprite(new cc.Sprite(gpNamespace.game.Game_blacktonghuashun),new tyNamespace.maskSprite(gpNamespace.game.Game_writetonghuashun),
    			this.fivetishiCallbackFunction, this);
    	tonghuashun.setUserData(16);
    	
    	var totleMenu = new cc.Menu(shunzi, tonghua, fulao, sitiao, tonghuashun);

    	totleMenu.attr({
    		x: 300 + 658 / 2,
    		y: 0 + 78 / 2
    	});
    	totleMenu.alignItemsHorizontallyWithPadding(-25);
    	chuButtonLayer.addChild(totleMenu, 50);*/

    	//不出按钮
    	var noplayItem = new cc.MenuItemSprite(new cc.Sprite(gpNamespace.pdkgame.Game_buttonnochu),new tyNamespace.maskSprite(gpNamespace.pdkgame.Game_buttonnochu),
    			this.nochuCallbackFunction, this);
    	noplayItem.attr({
    		x:102 / 2,
    		y:102 / 2
    	});
    	noplayItem.setScale(0.8);
    	var noplayMenu = new cc.Menu(noplayItem);
    	noplayMenu.attr({
    		x:239 + 180 / 2 - 50,
    		y:228 + 94 /2 - 110
    	});
    	chuButtonLayer.addChild(noplayMenu);

    	//重选按钮，提示按钮，出牌按钮
    	var gravity = new cc.MenuItemSprite(new cc.Sprite(gpNamespace.pdkgame.Game_buttonreelected),new tyNamespace.maskSprite(gpNamespace.pdkgame.Game_buttonreelected),
    			this.chongxuanCallbackFunction, this);
    	var prompt = new cc.MenuItemSprite(new cc.Sprite(gpNamespace.pdkgame.Game_buttonreminder),new tyNamespace.maskSprite(gpNamespace.pdkgame.Game_buttonreminder),
    			this.tishiCallbackFunction, this);
    	var play = new cc.MenuItemSprite(new cc.Sprite(gpNamespace.pdkgame.Game_buttonchupai),new tyNamespace.maskSprite(gpNamespace.pdkgame.Game_buttonchupai),
    			this.chupaiCallbackFunction, this);
    	gravity.setScale(0.8);
    	prompt.setScale(0.8);
    	play.setScale(0.8);
    	var totleMenu = new cc.Menu(gravity, prompt, play);
    	
    	totleMenu.setContentSize(480, 80);
    	
    	totleMenu.attr({
    		x: 450 + 604 / 2,
    		y: 228 + 190 / 2 - 110
    	});
    	totleMenu.alignItemsHorizontally();
    	chuButtonLayer.addChild(totleMenu,2);
    },
    
    tuoguanCallbackFunction:function(){
    	cc.log("托管");
    },

    //各种回调函数汇总
    nochuCallbackFunction: function (sender) {
//  	gpNamespace.playEffect(gpNamespaces.ButtonBack, false);
    	gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

    	tyNamespace.setMenuEnable(sender);
    	gpNamespace.sendOutCards([]);
    },
    
    chongxuanCallbackFunction:function(sender){
    	gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

    	tyNamespace.setMenuEnable(sender);
    	this.resetTilesClick();
    },

    chupaiCallbackFunction: function (sender) {
    	gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

    	tyNamespace.setMenuEnable(sender);
    	if(this.getChuTiles().length != 0) {//没有提起的牌，不执行下面的语句
    		gpNamespace.sendOutCards(this.getChuTiles());   //客户端给服务器发送信息
    	} else{
    		this.showWrongMsg();
    	}
    },

    //出牌是否可以出？返回
    onCurrentAtNotifyLabel:function (canChu) {
    	cc.log("出牌是否可以出？返回 onCurrentAtNotifyLabel" + canChu);
    	if (canChu == 1)
    		this.showWrongMsg();
    },
    
    showWrongMsg: function () {
    	var blackL = this.blackLabel;
    	blackL.setVisible(true);
    	blackL.runAction(cc.sequence(cc.delayTime(1.5), cc.callFunc(function () {
    		blackL.setVisible(false);
    	})));

    	var guize = this.guize;
    	guize.setVisible(true);

    	guize.runAction(cc.sequence(cc.delayTime(1.5), cc.callFunc(function () {
    		guize.setVisible(false);
    	})));
    	this.resetTilesClick();
    },

    //cardNotify,tishiCallbackFunction
    tishiCallbackFunction: function (sender) {
    	gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

    	tyNamespace.setMenuEnable(sender);
    	gpNamespace.prompt();
    },

    fivetishiCallbackFunction:function (sender) {
    	gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

    	tyNamespace.setMenuEnable(sender);
    	var type = sender.getUserData();
    	gpNamespace.fivePrompt(type);
    },
    

    //出牌牌型提示方法
    onCurrentAtNotifyLabel:function (canChu){
    	cc.log("canChu" + canChu);
    	if(canChu == 1){
    		cc.log("牌型不正确");

    		var blackL = this.blackLabel;
    		blackL.setVisible(true);
    		blackL.runAction(cc.sequence(cc.delayTime(1), cc.callFunc(function () {
    			blackL.setVisible(false);
    		})));
    		
    		var guize = this.guize;
    		guize.setVisible(true);

    		guize.runAction(cc.sequence(cc.delayTime(1), cc.callFunc(function () {
    			guize.setVisible(false);
    		})));
    		this.resetTilesClick();
    	}
    },
    
    //cardNotify,tishiCallbackFunction
    tishiCallbackFunction: function (sender) { 
    	gpNamespace.prompt();
    		
    },
    
    fivetishiCallbackFunction:function (sender){
    	var type = sender.getUserData();
    	gpNamespace.fivePrompt(type);
    },

    //出牌提示牌型抬起  
    cardNotify:function (tiles){   	
    	if(tiles.length == 0){
    		cc.log("没有大过上家的牌");
    		var spriteRemoved = this.getChildByName("spriteRemoved");
    		if (spriteRemoved) {
    			cc.log("cardNotify 删除 spriteRemoved");
    			spriteRemoved.removeAllChildren(true);
    		}

    		var genderString = "boy";
    		if (!this.player.userItem.gender)
    			genderString = "girl";

    		var random = Math.floor(Math.random() * 3);
    		gpNamespace.SoundManager.playEffect("res/ty/sound/" + genderString + "/pass" + random + ".mp3", false);

    		var blackL = this.blackLabel;
    		blackL.setVisible(true);
    		blackL.runAction(cc.sequence(cc.delayTime(1), cc.callFunc(function () {
    			blackL.setVisible(false);
    		})));

    		var less = this.lessSprite;
    		less.setVisible(true);
    		less.runAction(cc.sequence(cc.delayTime(1), cc.callFunc(function () {
    			less.setVisible(false);
    		})));

    		this.noChu();
    	}else {
    		for (var i = 0; i < tiles.length; i++) {
    			var tile = tiles[i];
    			var haveTile = gpNamespace.CardActions.getTile(tile, this.player.handTiles);
    			this.tileUp(haveTile);
    			cc.log("tile" + tile.num);
    		}
    	}
    },
   
    getChuTiles: function () {
    	var handTiles = this.player.handTiles;
    	var chuTiles = [];

    	for (var i = 0; i < handTiles.length; i++) {
    		var tile = handTiles[i];
    		if (tile.clickTime == 1)
    			chuTiles.push(tile);
    	}
    	//把提示的牌打出去
//    	this.cardtypeNotify(chuTiles);
//    	gpNamespace.sendOutCards(this.getChuTiles());
    	return chuTiles;
    },

    resetTilesClick: function () {
    	var handTiles = this.player.handTiles;

    	for (var i = 0; i < handTiles.length; i++) {
    		var tile = handTiles[i];
    		if (tile.clickTime == 1) {
    			this.tileUp(tile);
    		}   
    	}
    },

    removeChuButtonLayer: function (sender) {
    	if (this.getChildByTag(3) != null)
    		this.removeChildByTag(3);
    },

    onExit: function () {
    	cc.eventManager.removeListeners(this);
    	this._super();
    },

});
